<?php
namespace Admin\Controller;

class DbController extends BaseController{
	public function index(){
		$rows = $size = $free = 0;
		$Common = D('Common');
		$object = $Common->info();
		if ($object){
			foreach ($object as $key=>$value){
				$object[$key]['size'] = number_format(($value['Index_length'] + $value['Data_length']) / 1024,1,'.','');
				$rows += $value['Rows'];
				$size += $object[$key]['size'];
				$object[$key]['size'] = $object[$key]['size']<1024 ? $object[$key]['size'].' KB' : number_format($object[$key]['size'] / 1024,1,'.','').' MB';
				$free += $value['Data_free'];
			}
		}
		$this->assign('All',$object);
		$this->assign('TableCount',count($object));
		$this->assign('Rows',$rows);
		$this->assign('Size',$size<1024 ? $size.' KB' : number_format($size / 1024,1,'.','').' MB');
		$this->assign('Free',$free);
		$this->display();
	}
	
	public function optimize(){
		$Common = D('Common');
		$object = $Common->info();
		if ($object){
			foreach ($object as $value){
				$Common->optimizeTable($value['Name']);
			}
		}
		$this->success(C('PREV_URL'),'数据表优化成功！');
	}
	 
	public function repairAutoindex(){
		$Common = D('Common');
		$object = $Common->info();
		if ($object){
			foreach ($object as $value){
				$Common->repairAutoindex($value['Name']);
			}
		}
		$this->success(C('PREV_URL'),'Autoindex修复成功！');
	}
}